package com.skivingcloud.admin.sys.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.Table;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Email;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;
import org.springframework.security.core.GrantedAuthority;

import java.io.Serializable;
import java.time.LocalDateTime;
import java.util.List;
import java.util.StringJoiner;

/**
 *  实体类。
 *
 * @author skivingcloud
 * @since 2023-08-28
 */
@Table(value = "sys_user")
@Schema(name = "SysUser对象", title = "系统用户")
@JsonIgnoreProperties(ignoreUnknown = true)
public class SysUser implements Serializable {

    @Id
    private String id;

    /**
     * 用户名
     */
    @NotBlank(message = "用户名不能为空")
    @Size(max = 50, message = "用户名长度不能超过50")
    @Schema(title = "用户名")
    private String username;

    /**
     * 密码
     */
    private String password;

    /**
     * 盐
     */
    private String salt;

    /**
     * 邮箱
     */
    @Email(message = "邮箱格式不合法")
    @Size(max = 100, message = "邮箱长度不能超过255")
    @Schema(title = "邮箱")
    private String email;

    /**
     * 手机号
     */
    @Size(max = 100, message = "手机号长度不能超过255")
    @Schema(title = "手机号")
    private String mobile;

    /**
     * 用户状态：100201-正常、100202-锁定、100203-停用、100204-删除
     */
    @NotBlank(message = "状态不能为空")
    @Size(max = 6, message = "状态长度不能超过6")
    @Schema(title = "用户状态：100201-正常、100202-锁定、100203-停用、100204-删除")
    private String status;

    /**
     * 创建者
     */
    @Schema(title = "创建者")
    private String createUserId;

    /**
     * 创建时间
     */
    @Schema(title = "创建时间")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime createTime;

    /**
     * 员工编号
     */
    @Size(max = 50, message = "员工编号长度不能超过50")
    @Schema(title = "员工编号")
    private String staffId;

    /**
     * ERP企业编号
     */
    @Size(max = 40, message = "企业编号长度不能超过6")
    @Schema(title = "ERP企业编号")
    private String enterpriseId;

    /**
     * ERP企业名称
     */
    @Size(max = 255, message = "企业名称长度不能超过255")
    @Schema(title = "ERP企业名称")
    private String enterpriseName;

    /**
     * 姓名
     */
    @NotBlank(message = "姓名不能为空")
    @Size(max = 50, message = "姓名长度不能超过50")
    @Schema(title = "姓名")
    private String staffName;

    /**
     * 证件类型 01-居民身份证、02-居民户口薄、03-驾驶证、04-军官证、05-士兵证、06-军官离退休证、07-中国护照、08-异常身份证、09-港澳台通行证、10-台湾通行证、11-回乡证、51-外国护照、52-旅行证、53-居留证件、71-组织机构代码证、72-税务登记证、73-营业执照、99-其他证件
     */
    @Size(max = 6, message = "证件类型长度不能超过6")
    @Schema(title = "证件类型 01-居民身份证、02-居民户口薄、03-驾驶证、04-军官证、05-士兵证、06-军官离退休证、07-中国护照、08-异常身份证、09-港澳台通行证、10-台湾通行证、11-回乡证、51-外国护照、52-旅行证、53-居留证件、71-组织机构代码证、72-税务登记证、73-营业执照、99-其他证件")
    private String idType;

    /**
     * 证件号码
     */
    @Size(max = 50, message = "证件号码长度不能超过50")
    @Schema(title = "证件号码")
    private String idNo;

    /**
     * 最后修改人
     */
    @Schema(title = "最后修改人")
    private String lastChangeder;

    /**
     * 最后修改时间
     */
    @Schema(title = "最后修改时间")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime lastChangedTime;

    /**
     * 最后修改密码时间
     */
    @Schema(title = "最后修改密码时间")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime lastChangedPwdTime;

    /**
     * 登录错误次数
     */
    @Schema(title = "登录错误次数")
    private Integer errorTime;

    /**
     * 登录状态(0-未登录 1-已登录)
     */
    @Schema(title = "登录状态(0-未登录 1-已登录)")
    private String loginStatus;

    /**
     * 提醒修改密码周期(单位：天)
     */
    @Schema(title = "提醒修改密码周期(单位：天)")
    private Integer alterTime;

    /**
     * 最后登录时间
     */
    @Schema(title = "最后登录时间")
    @JsonDeserialize(using = LocalDateTimeDeserializer.class)
    @JsonSerialize(using = LocalDateTimeSerializer.class)
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    private LocalDateTime loginTime;

    /**
     * 排序
     */
    @Schema(title = "排序")
    private Integer orderNum;

    /**
     * 审核状态
     */
    @Schema(title = "审核状态")
    private String chkStatus;

    /**
     * 组织机构
     */
    @Size(max = 32, message = "组织机构id长度不能超过32")
    @Schema(title = "组织机构")
    private String orgId;

    /**
     * 当前皮肤
     */
    @Schema(title = "当前皮肤")
    private String skin;

    /**
     * 对接外部系统识别账号
     */
    @Schema(title = "对接外部系统识别账号")
    private String accountName;

    /**
     * 上次登录终端：1-PC、2-APP
     */
    @Schema(title = "上次登录终端：1-PC、2-APP")
    private String loginTerminal;

    /**
     * 租户
     */
    @Schema(title = "租户")
    private String tenantId;
    
    @Column(ignore = true)
    private List<GrantedAuthority> grantedAuthorities;
    
    @Column(ignore = true)
    private String token;
    
    @Column(ignore = true)
    private String tenantName;
    
    @Column(ignore = true)
    private String orgName;
    
    @Column(ignore = true)
    private List<String> roleIds;
    
    @Column(ignore = true)
    private List<String> stationIds;
    
    @Column(ignore = true)
    private List<String> menuIds;
    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getSalt() {
        return salt;
    }

    public void setSalt(String salt) {
        this.salt = salt;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getMobile() {
        return mobile;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getCreateUserId() {
        return createUserId;
    }

    public void setCreateUserId(String createUserId) {
        this.createUserId = createUserId;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }

    public String getStaffId() {
        return staffId;
    }

    public void setStaffId(String staffId) {
        this.staffId = staffId;
    }

    public String getEnterpriseId() {
        return enterpriseId;
    }

    public void setEnterpriseId(String enterpriseId) {
        this.enterpriseId = enterpriseId;
    }

    public String getEnterpriseName() {
        return enterpriseName;
    }

    public void setEnterpriseName(String enterpriseName) {
        this.enterpriseName = enterpriseName;
    }

    public String getStaffName() {
        return staffName;
    }

    public void setStaffName(String staffName) {
        this.staffName = staffName;
    }

    public String getIdType() {
        return idType;
    }

    public void setIdType(String idType) {
        this.idType = idType;
    }

    public String getIdNo() {
        return idNo;
    }

    public void setIdNo(String idNo) {
        this.idNo = idNo;
    }

    public String getLastChangeder() {
        return lastChangeder;
    }

    public void setLastChangeder(String lastChangeder) {
        this.lastChangeder = lastChangeder;
    }

    public LocalDateTime getLastChangedTime() {
        return lastChangedTime;
    }

    public void setLastChangedTime(LocalDateTime lastChangedTime) {
        this.lastChangedTime = lastChangedTime;
    }

    public LocalDateTime getLastChangedPwdTime() {
        return lastChangedPwdTime;
    }

    public void setLastChangedPwdTime(LocalDateTime lastChangedPwdTime) {
        this.lastChangedPwdTime = lastChangedPwdTime;
    }

    public Integer getErrorTime() {
        return errorTime;
    }

    public void setErrorTime(Integer errorTime) {
        this.errorTime = errorTime;
    }

    public String getLoginStatus() {
        return loginStatus;
    }

    public void setLoginStatus(String loginStatus) {
        this.loginStatus = loginStatus;
    }

    public Integer getAlterTime() {
        return alterTime;
    }

    public void setAlterTime(Integer alterTime) {
        this.alterTime = alterTime;
    }

    public LocalDateTime getLoginTime() {
        return loginTime;
    }

    public void setLoginTime(LocalDateTime loginTime) {
        this.loginTime = loginTime;
    }

    public Integer getOrderNum() {
        return orderNum;
    }

    public void setOrderNum(Integer orderNum) {
        this.orderNum = orderNum;
    }

    public String getChkStatus() {
        return chkStatus;
    }

    public void setChkStatus(String chkStatus) {
        this.chkStatus = chkStatus;
    }

    public String getOrgId() {
        return orgId;
    }

    public void setOrgId(String orgId) {
        this.orgId = orgId;
    }

    public String getSkin() {
        return skin;
    }

    public void setSkin(String skin) {
        this.skin = skin;
    }

    public String getAccountName() {
        return accountName;
    }

    public void setAccountName(String accountName) {
        this.accountName = accountName;
    }

    public String getLoginTerminal() {
        return loginTerminal;
    }

    public void setLoginTerminal(String loginTerminal) {
        this.loginTerminal = loginTerminal;
    }

    public String getTenantId() {
        return tenantId;
    }

    public void setTenantId(String tenantId) {
        this.tenantId = tenantId;
    }
    
    public List<GrantedAuthority> getGrantedAuthorities(){
        return grantedAuthorities;
    }
    
    public void setGrantedAuthorities(List<GrantedAuthority> grantedAuthorities){
        this.grantedAuthorities = grantedAuthorities;
    }
    
    public String getToken(){
        return token;
    }
    
    public void setToken(String token){
        this.token = token;
    }
    
    @Override
    public String toString(){
        return new StringJoiner(", ", SysUser.class.getSimpleName() + "[", "]")
                .add("id='" + id + "'")
                .add("username='" + username + "'")
                .add("password='" + password + "'")
                .add("salt='" + salt + "'")
                .add("email='" + email + "'")
                .add("mobile='" + mobile + "'")
                .add("status='" + status + "'")
                .add("createUserId='" + createUserId + "'")
                .add("createTime=" + createTime)
                .add("staffId='" + staffId + "'")
                .add("enterpriseId='" + enterpriseId + "'")
                .add("enterpriseName='" + enterpriseName + "'")
                .add("staffName='" + staffName + "'")
                .add("idType='" + idType + "'")
                .add("idNo='" + idNo + "'")
                .add("lastChangeder='" + lastChangeder + "'")
                .add("lastChangedTime=" + lastChangedTime)
                .add("lastChangedPwdTime=" + lastChangedPwdTime)
                .add("errorTime=" + errorTime)
                .add("loginStatus='" + loginStatus + "'")
                .add("alterTime=" + alterTime)
                .add("loginTime=" + loginTime)
                .add("orderNum=" + orderNum)
                .add("chkStatus='" + chkStatus + "'")
                .add("orgId='" + orgId + "'")
                .add("skin='" + skin + "'")
                .add("accountName='" + accountName + "'")
                .add("loginTerminal='" + loginTerminal + "'")
                .add("tenantId='" + tenantId + "'")
                .add("grantedAuthorities=" + grantedAuthorities)
                .add("token='" + token + "'")
                .toString();
    }
    
    public String getTenantName(){
        return tenantName;
    }
    
    public void setTenantName(String tenantName){
        this.tenantName = tenantName;
    }
    
    public String getOrgName(){
        return orgName;
    }
    
    public void setOrgName(String orgName){
        this.orgName = orgName;
    }
    
    public List<String> getRoleIds(){
        return roleIds;
    }
    
    public void setRoleIds(List<String> roleIds){
        this.roleIds = roleIds;
    }
    
    public List<String> getStationIds(){
        return stationIds;
    }
    
    public void setStationIds(List<String> stationIds){
        this.stationIds = stationIds;
    }
    
    public List<String> getMenuIds(){
        return menuIds;
    }
    
    public void setMenuIds(List<String> menuIds){
        this.menuIds = menuIds;
    }
}
